<!-- <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">后台管理</a>
            <a class="navbar-brand" href="">退出</a>
        </div>
    </div>
</nav> -->


<nav>
    <div class="container-fluid navbar-fixed-top bg-primary">
        <ul class="nav navbar-nav  left">
            <li class="text-white h4">
                &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-leaf"></span>&nbsp;&nbsp;<b>物资管理调度系统</b>
            </li>
        </ul>
        <ul class="nav navbar-nav nav-pills right ">
            <li class="bg-danger">
                <a href="#"><span class="glyphicon glyphicon-bell"></span></a>
            </li>
            <li class="bg-info dropdown">
                <a class="dropdown-toggle" href="#" data-toggle="dropdown">
                    <span class="glyphicon glyphicon-user"></span>&nbsp;<span>系统管理员</span><span class="caret"></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-right">
                    <li class="text-center"><a href="#"><span class="text-primary">账号设置</span></a></li>
                    <li class="text-center"><a href="#"><span class="text-primary">消息设置</span></a></li>
                    <li class="text-center"><a href="#"><span class="text-primary">帮助中心</span></a></li>
                    <li class="divider"><a href="#"></a></li>
                    <li class="text-center"><a href="<?=site_url('manage/logout')?>"><span class="text-primary">退出</span></a></li>
                </ul>
            </li>
        </ul>
    </div>
</nav>

<div class="upload_div"></div>
<link rel="stylesheet" type="text/css" href="<?=base_url()?>public/css/jquery-ui.css">
<script type="text/javascript" src="public/js/jquery-ui.js"></script>

<script type="text/javascript">


/*
 * 图片上传开始
 */
var column = null;
function fileSelected(userfile,o) {
    column = o;
    // imgUrl = "selected";
    uploadFile(userfile);
}

function uploadFile(userfile) {
    console.log("userfile.files[0]",userfile.files[0])
    userfileShowDisc=userfile;
    var fd = new FormData();
    fd.append("userfile",userfile.files[0]);
    console.log("fd",fd)
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", uploadProgress, false);
    xhr.addEventListener("load", uploadComplete, false);
    xhr.addEventListener("error", uploadFailed, false);
    xhr.addEventListener("abort", uploadCanceled, false);
    xhr.open("POST", "<?=site_url('manage/do_upload')?>");
    xhr.send(fd);
}

function uploadProgress(evt) {
    if (evt.lengthComputable) {
        var percentComplete = Math.round(evt.loaded * 100 / evt.total);
        console.log(percentComplete)
        // $(".post_img_inp").html('图片上传中'+percentComplete + '%');
    }else {
    }
}

function uploadComplete(evt) {
    var json = eval('(' + evt.target.responseText + ')');
    console.log(json)
    if (json.status=='success') {
        console.log(json.imagePath)

        $('.'+column).val(json.imagePath)
        alert('上传完成')
        // imgUrl = json.imagePath;
        // $(".post_img_box img").attr('src',json.imagePath);
        // $(".post_img_inp").html('重新选择图片');
    }else{
        alert('图片上传失败。')
    }
    //隐藏域
    // $(userfileShowDisc).next().find("img[name='img']").attr("src",json.model.fileName);
}

function uploadFailed(evt) {
    alert("上传失败");
}

function uploadCanceled(evt) {
    // alert("已经取消上传");
}





function addfile(s,v){
    $("#"+s).val(v);
}

function hide_div(){
    $(function(){
        $(".upload_div").hide();
    })
}

</script>
